/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.form;

import org.rails.extjs.Option;
import org.rails.extjs.data.Store;

public class TimeField extends ComboBox {

	public TimeField() {
		super();
	}

	public TimeField(Option configOptions) {
		super(configOptions);
	}
	
	public TimeField(String name) {
		super(name);
	}
	
	public TimeField(String name, String fieldLabel) {
		super(name, fieldLabel);
	}

	public TimeField(String name, String fieldLabel,String value) {
		super(name, fieldLabel,value);
	}

	public TimeField(String name, String fieldLabel, String value, Store store) {
		super(name, fieldLabel, value, store);
	}

	public void setAltFormats(String altFormats) {
		addOption("altFormats", altFormats);
	}

	public String getAltFormats() {
		return getString("altFormats",
				"g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H");
	}
	
	public void setFormat(String format){
		addOption("format", format);
	}
	
	public String getFormat(){
		return getString("format","");
	}
	
	public void setIncrement(Integer increment){
		addOption("increment", increment);
	}
	
	public Integer getIncrement(){
		return getInteger("increment", 15);
	}
	
	public void setInvalidText(String invalidText){
		addOption("invalidText", invalidText);
	}
	
	public String getInvalidText(){
		return getString("invalidText", "{value} is not a valid time");
	}
	
	public void setMaxText(String maxText){
		addOption("maxText", maxText);
	}
	
	public String getMaxText(){
		return getString("maxText","The time in this field must be equal to or before {0}");
	}
	
	public void setMaxValue(String maxValue){
		addOption("maxValue",maxValue);
	}
	
	public String getMaxValue(){
		return getString("maxValue","");
	}
	
	public void setMinText(String minText){
		addOption("minText", minText);
	}
	
	public String getMinText(){
		return getString("minText","");
	}
	
	public void setMinValue(String minValue){
		addOption("minValue", minValue);
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.form.TimeField(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}
	

}
